package com.butnet.myframe.creator;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.List;

public class Creator {
	private String daoInterfacePackName = null;
	private String daoImplPackName = null;
	private String modelPackName = null;
	private String servicePackName = null;
	private String serviceImplPackName = null;
	private String actionPackName = null;
	private String formPackName = null;

	private File daoInterfacePackFolder = null;
	private File daoImplPackFolder = null;
	private File modelPackFolder = null;
	private File servicePackFolder = null;
	private File serviceImplPackFolder = null;
	private File actionPackFolder = null;
	private File formPackFolder = null;

	private File srcFolder = null;
	private File webRoot = null;

	private String actionRootURL = "";
	private String actionParameter = null;

	private List<String> modelClassName = new LinkedList<String>();

	public void setSrcFolder(File srcFolder) {
		this.srcFolder = srcFolder;
	}

	public File getSrcFolder() {
		return srcFolder;
	}

	public void setWebRoot(File webRoot) {
		this.webRoot = webRoot;
	}

	public File getWebRoot() {
		return webRoot;
	}

	public void setActionParameter(String actionParameter) {
		this.actionParameter = actionParameter;
	}

	public String getActionParameter() {
		return actionParameter;
	}

	public void setModelPackName(String modelPackName) {
		this.modelPackName = modelPackName;
		this.modelPackFolder = new File(srcFolder, modelPackName.replaceAll("\\.", "/"));
	}

	public String getModelPackName() {
		return modelPackName;
	}

	public File getModelPackFolder() {
		return modelPackFolder;
	}

	public void setDaoInterfacePackName(String daoInterfacePackName) {
		this.daoInterfacePackName = daoInterfacePackName;
		this.daoInterfacePackFolder = new File(srcFolder, daoInterfacePackName.replaceAll("\\.", "/"));
	}

	public String getDaoInterfacePackName() {
		return daoInterfacePackName;
	}

	public File getDaoInterfacePackFolder() {
		return daoInterfacePackFolder;
	}

	public void setDaoImplPackName(String daoImplPackName) {
		this.daoImplPackName = daoImplPackName;
		this.daoImplPackFolder = new File(srcFolder, daoImplPackName.replaceAll("\\.", "/"));
	}

	public String getDaoImplPackName() {
		return daoImplPackName;
	}

	public File getDaoImplPackFolder() {
		return daoImplPackFolder;
	}

	public void setServicePackName(String servicePackName) {
		this.servicePackName = servicePackName;
		this.serviceImplPackName = servicePackName + ".impl";

		this.servicePackFolder = new File(srcFolder, servicePackName.replaceAll("\\.", "/"));
		this.serviceImplPackFolder = new File(srcFolder, this.serviceImplPackName.replaceAll("\\.", "/"));
	}

	public String getServicePackName() {
		return servicePackName;
	}

	public File getServicePackFolder() {
		return servicePackFolder;
	}

	public String getServiceImplPackName() {
		return serviceImplPackName;
	}

	public File getServiceImplPackFolder() {
		return serviceImplPackFolder;
	}

	public void setActionPackName(String actionPackName) {
		this.actionPackName = actionPackName;
		this.actionPackFolder = new File(srcFolder, actionPackName.replaceAll("\\.", "/"));
	}

	public String getActionPackName() {
		return actionPackName;
	}

	public File getActionPackFolder() {
		return actionPackFolder;
	}

	public void setFormPackName(String formPackName) {
		this.formPackName = formPackName;
		this.formPackFolder = new File(srcFolder, formPackName.replaceAll("\\.", "/"));
	}

	public File getFormPackFolder() {
		return formPackFolder;
	}

	public String getFormPackName() {
		return formPackName;
	}

	public void setActionRootURL(String actionRootURL) {
		this.actionRootURL = actionRootURL;
	}

	public String getActionRootURL() {
		return actionRootURL;
	}

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		Creator creator = new Creator();
		creator.setSrcFolder(new File("../a/src"));
		creator.setWebRoot(new File("../a/WebContent"));
		creator.setActionRootURL("/action");
		creator.setActionParameter("fun");
		creator.setModelPackName("com.cdjtxxg.officeautomation.im.dao.model");
		creator.setDaoInterfacePackName("com.cdjtxxg.officeautomation.im.dao");
		creator.setDaoImplPackName("com.cdjtxxg.officeautomation.im.dao.hibernate");
		creator.setServicePackName("com.cdjtxxg.officeautomation.im.service");
		creator.setActionPackName("com.cdjtxxg.officeautomation.im.web.action");
		creator.setFormPackName("com.cdjtxxg.officeautomation.im.web.form");

		creator.checkModelClasses();

		creator.createDaosInterface();
		creator.createDaoFactory();
		creator.createServiceFactory();
		creator.copyDataBaseProperties();
		creator.copyStruts();
		creator.copyStrutsMessage();
		creator.copyApplicationContextResouse();
		creator.copyApplicationContextHibernate();
		creator.copyApplicationContextDao();
		creator.copyApplicationContextStruts();
		creator.copyLibs();
	}

	private void copyLibs() {
		InputStream in = null;
		BufferedReader reader = null;
		List<String> libs = new LinkedList<String>();
		try {
			in = Creator.class.getResourceAsStream("/com/butnet/myframe/creator/libs.conf");
			if(in==null)return;
			reader = new BufferedReader(new InputStreamReader(in));
			String line = null;
			while((line=reader.readLine())!=null){
				line = line.trim();
				if(line.startsWith("#")||line.startsWith("!")||line.startsWith("//"))continue;
				libs.add(line);
			}
		} catch (Exception e) {
			e.printStackTrace(System.err);
		} finally {
			try {
				if (reader != null)
					reader.close();
				if (in != null)
					in.close();
			} catch (Exception e) {
			}
		}
		File libRoot = new File(webRoot,"WEB-INF/lib");
		libRoot.mkdirs();
		for(String lib : libs){
			copyLib(lib, libRoot);
		}
	}

	private void copyLib(String lib, File libDir) {
		InputStream in = null;
		FileOutputStream out = null;
		try {
			in = Creator.class.getResourceAsStream("/com/butnet/myframe/res/lib/"+lib);
			if(in==null)return;
			out = new FileOutputStream(new File(libDir, lib));
			byte[] buf = new byte[1024*3];
			int num;
			while((num=in.read(buf))!=-1){
				out.write(buf,0,num);
			}
		} catch (Exception e) {
			e.printStackTrace(System.err);
		} finally {
			try {
				if (in != null)
					in.close();
				if(out!=null)out.close();
			} catch (Exception e) {
			}
		}
	}

	public void create() throws IOException {
		checkModelClasses();

		createDaosInterface();
		createDaoFactory();
		createServiceFactory();
		copyDataBaseProperties();
		copyStruts();
		copyStrutsMessage();
		copyApplicationContextResouse();
		copyApplicationContextHibernate();
		copyApplicationContextDao();
		copyApplicationContextStruts();
	}

	private void checkModelClasses() {
		File[] files = modelPackFolder.listFiles();
		for (File f : files) {
			if (f.isFile()) {
				if (!f.getName().toLowerCase().endsWith(".java"))
					continue;
				String name = f.getName().substring(0, f.getName().lastIndexOf('.'));
				modelClassName.add(name);
			}
		}
	}

	private void copyDataBaseProperties() throws IOException {
		// Copy DataBaseProperties
		InputStream in = Creator.class.getResourceAsStream("/com/butnet/myframe/res/database.properties");
		byte[] buf = new byte[1024 * 10];
		int num;
		FileOutputStream out = new FileOutputStream(new File(srcFolder, "database.properties"));
		while ((num = in.read(buf)) != -1) {
			out.write(buf, 0, num);
		}
		out.close();
		in.close();
	}

	private void copyStrutsMessage() throws IOException {
		// Copy MessageResources
		InputStream in = Creator.class.getResourceAsStream("/com/butnet/myframe/res/MessageResources.properties");
		byte[] buf = new byte[1024 * 10];
		int num;
		FileOutputStream out = new FileOutputStream(new File(srcFolder, "MessageResources.properties"));
		while ((num = in.read(buf)) != -1) {
			out.write(buf, 0, num);
		}
		out.close();
		in.close();
	}

	private void copyStruts() throws IOException {
		// Copy Struts
		PrintStream writer = new PrintStream(new File(webRoot, "WEB-INF/struts-config.xml"));
		writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		writer
				.println("<!DOCTYPE struts-config PUBLIC \"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN\" \"http://struts.apache.org/dtds/struts-config_1_2.dtd\">");
		writer.println("<struts-config>");
		writer.println("	<data-sources>");
		writer.println("	</data-sources>");
		writer.println("	<form-beans>");
		String formName = null;
		for (String s : modelClassName) {
			formName = s.substring(0, 1).toLowerCase() + s.substring(1) + "Form";
			writer.println("		<form-bean name=\"" + formName + "\" type=\"" + formPackName + "." + s
					+ "Form\"></form-bean>");
		}
		writer.println("	</form-beans>");
		writer.println("	<global-exceptions>");
		writer.println("	</global-exceptions>");
		writer.println("	<global-forwards>");
		writer.println("	</global-forwards>");
		writer.println("	<action-mappings>");
		String _actionRoot = actionRootURL;
		if (_actionRoot == null)
			_actionRoot = "";
		if (!_actionRoot.startsWith("/"))
			_actionRoot = "/" + _actionRoot;
		if (!_actionRoot.endsWith("/"))
			_actionRoot += "/";
		String actionName = null;
		for (String s : modelClassName) {
			formName = s.substring(0, 1).toLowerCase() + s.substring(1) + "Form";
			actionName = s.substring(0, 1).toLowerCase() + s.substring(1) + "Action";

			writer.println("		<action path=\"" + _actionRoot + actionName
					+ "\" type=\"org.springframework.web.struts.DelegatingActionProxy\" name=\"" + formName
					+ "\" attribute=\"" + formName + "\" parameter=\"" + actionParameter + "\" scope=\"request\">");
			writer.println("			<!-- <forward name=\"forwardName\" path=\"/url\"></forward> -->");
			writer.println("		</action>");
		}
		writer.println("	</action-mappings>");

		writer.println("	<message-resources parameter=\"MessageResources\" />");

		writer.println("	<plug-in className=\"org.springframework.web.struts.ContextLoaderPlugIn\">");
		writer
				.println("		<set-property property=\"contextConfigLocation\" value=\"classpath:applicationContext-dao.xml classpath:applicationContext-hibernate.xml classpath:applicationContext-resouse.xml classpath:applicationContext-struts.xml\" />");
		writer.println("	</plug-in>");
		writer.println("</struts-config>");
		writer.close();
	}

	private void copyApplicationContextResouse() throws IOException {
		// Copy ApplicationContextResouse
		InputStream in = Creator.class.getResourceAsStream("/com/butnet/myframe/res/applicationContext-resouse.xml");
		byte[] buf = new byte[1024 * 10];
		int num;
		FileOutputStream out = new FileOutputStream(new File(srcFolder, "applicationContext-resouse.xml"));
		while ((num = in.read(buf)) != -1) {
			out.write(buf, 0, num);
		}
		out.close();
		in.close();
	}

	private void copyApplicationContextHibernate() throws IOException {
		PrintStream writer = new PrintStream(new File(srcFolder, "applicationContext-hibernate.xml"));
		writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		writer
				.println("<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN 2.0//EN\" \"http://www.springframework.org/dtd/spring-beans-2.0.dtd\">");
		writer.println("<beans>");
		writer
				.println("	<bean id=\"sessionFactory\" class=\"org.springframework.orm.hibernate3.LocalSessionFactoryBean\">");
		writer.println("		<property name=\"dataSource\" ref=\"dataSource\" />");
		writer.println("		<property name=\"hibernateProperties\">");
		writer.println("			<props>");
		writer.println("				<prop key=\"hibernate.dialect\">${hibernate.dialect}</prop>");
		writer.println("			</props>");
		writer.println("		</property>");
		writer.println("		<property name=\"mappingResources\">");
		writer.println("			<list>");
		for (String s : modelClassName) {
			writer.println("				<value>" + modelPackName.replaceAll("\\.", "/") + "/" + s + ".hbm.xml</value>");
		}
		writer.println("			</list>");
		writer.println("		</property>");
		writer.println("	</bean>");
		writer.println("</beans>");
		writer.close();
	}

	private void copyApplicationContextDao() throws IOException {
		PrintStream writer = new PrintStream(new File(srcFolder, "applicationContext-dao.xml"));
		writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		writer.println("<beans xmlns=\"http://www.springframework.org/schema/beans\"");
		writer.println("	xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
		writer
				.println("	xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd\">");
		writer.println("	<!-- Dao -->");
		String name = null;
		for (String s : modelClassName) {
			name = s.substring(0, 1).toLowerCase() + s.substring(1);
			writer.println("	<bean id=\"" + name + "Dao\" class=\"" + daoImplPackName + "." + s + "DaoImpl\">");
			writer.println("		<property name=\"debug\" value=\"true\"></property>");
			writer.println("		<property name=\"sessionFactory\" ref=\"sessionFactory\"></property>");
			writer.println("	</bean>");
			writer.println("	");
		}
		writer.println("	<!-- DaoFactory -->");
		writer.println("	<bean id=\"daoFactory\" class=\"" + daoInterfacePackName + ".DaoFactory\">");
		for (String s : modelClassName) {
			name = s.substring(0, 1).toLowerCase() + s.substring(1);
			writer.println("		<property name=\"" + name + "Dao\" ref=\"" + name + "Dao\"></property>");
		}
		writer.println("	</bean>");
		writer.println("</beans>");

		writer.close();
	}

	private void copyApplicationContextStruts() throws IOException {
		PrintStream writer = new PrintStream(new File(srcFolder, "applicationContext-struts.xml"));
		writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		writer.println("<beans xmlns=\"http://www.springframework.org/schema/beans\"");
		writer.println("	xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
		writer
				.println("	xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd\">");
		writer.println("	<!-- Service -->");
		String name = null;
		for (String s : modelClassName) {
			name = s.substring(0, 1).toLowerCase() + s.substring(1);
			writer.println("	<bean id=\"" + name + "Service\" class=\"" + serviceImplPackName + "." + s
					+ "ServiceImpl\">");
			writer.println("		<property name=\"" + name + "Dao\" ref=\"" + name + "Dao\"></property>");
			writer.println("		<property name=\"daoFactory\" ref=\"daoFactory\"></property>");
			writer.println("		<property name=\"debug\" value=\"true\"></property>");
			writer.println("	</bean>");
			writer.println("	");
		}

		writer.println("	<!-- ServiceFactory -->");
		writer.println("	<bean id=\"serviceFactory\" class=\"" + servicePackName + ".ServiceFactory\">");
		for (String s : modelClassName) {
			name = s.substring(0, 1).toLowerCase() + s.substring(1);
			writer.println("		<property name=\"" + name + "Service\" ref=\"" + name + "Service\"></property>");
		}
		writer.println("	</bean>");
		writer.println("	<!-- Action -->");
		String _actionRoot = actionRootURL;
		if (_actionRoot == null)
			_actionRoot = "";
		if (!_actionRoot.startsWith("/"))
			_actionRoot = "/" + _actionRoot;
		if (!_actionRoot.endsWith("/"))
			_actionRoot += "/";
		String actionName = null;
		for (String s : modelClassName) {
			actionName = s.substring(0, 1).toLowerCase() + s.substring(1) + "Action";
			writer.println("	<bean name=\"" + _actionRoot + actionName + "\" class=\"" + actionPackName + "." + s
					+ "Action\">");
			writer.println("		<property name=\"serviceFactory\" ref=\"serviceFactory\"></property>");
			writer.println("	</bean>");
		}
		writer.println("</beans>");

		writer.close();
	}

	private void createDaosInterface() throws IOException {
		for (String name : modelClassName) {
			createDaoInterface(name);
			createForm(name);
		}
	}

	private void createDaoFactory() throws IOException {
		daoInterfacePackFolder.mkdirs();
		PrintWriter writer = new PrintWriter(new FileWriter(new File(daoInterfacePackFolder, "DaoFactory.java")));
		writer.println("package " + daoInterfacePackName + ";");
		for (String s : modelClassName) {
			writer.println("import " + daoInterfacePackName + "." + s + "Dao;");
		}
		writer.println("import com.butnet.myframe.dao.IDaoFactory;");
		writer.println("public class DaoFactory implements IDaoFactory {");
		for (String s : modelClassName) {
			writer.println("	private " + s + "Dao " + s.substring(0, 1).toLowerCase() + s.substring(1) + "Dao;");
		}
		for (String s : modelClassName) {
			writer.println("	public " + s + "Dao get" + s + "Dao() {");
			writer.println("		return " + s.substring(0, 1).toLowerCase() + s.substring(1) + "Dao;");
			writer.println("	}");
			writer.println();
			writer.println("	public void set" + s + "Dao(" + s + "Dao " + s.substring(0, 1).toLowerCase()
					+ s.substring(1) + "Dao) {");
			writer.println("		this." + s.substring(0, 1).toLowerCase() + s.substring(1) + "Dao = "
					+ s.substring(0, 1).toLowerCase() + s.substring(1) + "Dao;");
			writer.println("	}");
			writer.println();
		}
		writer.println("}");
		writer.close();
	}

	private void createServiceFactory() throws IOException {
		servicePackFolder.mkdirs();
		PrintWriter writer = new PrintWriter(new FileWriter(new File(servicePackFolder, "ServiceFactory.java")));
		writer.println("package " + servicePackName + ";");
		for (String s : modelClassName) {
			writer.println("import " + servicePackName + "." + s + "Service;");
		}
		writer.println("import com.butnet.myframe.service.IServiceFactory;");
		writer.println("public class ServiceFactory implements IServiceFactory {");
		for (String s : modelClassName) {
			writer
					.println("	private " + s + "Service " + s.substring(0, 1).toLowerCase() + s.substring(1)
							+ "Service;");
		}
		for (String s : modelClassName) {
			writer.println("	public " + s + "Service get" + s + "Service() {");
			writer.println("		return " + s.substring(0, 1).toLowerCase() + s.substring(1) + "Service;");
			writer.println("	}");
			writer.println();
			writer.println("	public void set" + s + "Service(" + s + "Service " + s.substring(0, 1).toLowerCase()
					+ s.substring(1) + "Service) {");
			writer.println("		this." + s.substring(0, 1).toLowerCase() + s.substring(1) + "Service = "
					+ s.substring(0, 1).toLowerCase() + s.substring(1) + "Service;");
			writer.println("	}");
			writer.println();
		}
		writer.println("}");
		writer.close();
	}

	private void createForm(String name) throws IOException {
		formPackFolder.mkdirs();
		PrintWriter writer = new PrintWriter(new FileWriter(new File(formPackFolder, name + "Form.java")));
		writer.println("package " + formPackName + ";");
		writer.println("import org.apache.struts.action.ActionForm;");
		writer.println("public class " + name + "Form extends ActionForm {");

		String modelClass = modelPackName + "." + name;
		Class<?> cls = null;
		try {
			cls = Class.forName(modelClass);
		} catch (ClassNotFoundException e) {
			writer.close();
			new File(formPackFolder, name + "Form.java").delete();
			return;
		}
		List<String> properties = new LinkedList<String>();
		Method[] ms = cls.getMethods();
		for (Method m : ms) {
			if (m.getName().startsWith("get") && !m.getName().equals("getClass")) {
				properties.add(m.getName().substring("get".length()));
			}
		}

		writer.println("	private static final long serialVersionUID = 1L;");
		for (String p : properties) {
			writer.println("	private String " + p.substring(0, 1).toLowerCase() + p.substring(1) + " ;");
		}
		writer.println();

		for (String p : properties) {
			writer.println("	public String get" + p + " () {");
			writer.println("		return " + p.substring(0, 1).toLowerCase() + p.substring(1) + ";");
			writer.println("	}");
			writer.println();
			writer.println("	public void set" + p + " (String " + p.substring(0, 1).toLowerCase() + p.substring(1)
					+ ") {");
			writer.println("		this." + p.substring(0, 1).toLowerCase() + p.substring(1) + " = "
					+ p.substring(0, 1).toLowerCase() + p.substring(1) + ";");
			writer.println("	}");
			writer.println();
		}

		writer.println("}");
		writer.close();

		createAction(name);
	}

	private void createAction(String name) throws IOException {
		actionPackFolder.mkdirs();
		PrintWriter writer = new PrintWriter(new FileWriter(new File(actionPackFolder, name + "Action.java")));
		writer.println("package " + actionPackName + ";");
		writer.println("import " + formPackName + "." + name + "Form;");
		writer.println("import " + servicePackName + "." + name + "Service;");
		writer.println("import " + servicePackName.substring(0, servicePackName.lastIndexOf('.'))
				+ ".dao.hibernate.model." + name + ";");
		writer.println("import javax.servlet.http.HttpServletRequest;");
		writer.println("import javax.servlet.http.HttpServletResponse;");
		writer.println("import org.apache.struts.action.ActionForward;");
		writer.println("import org.apache.struts.action.ActionForm;");
		writer.println("import org.apache.struts.action.ActionMapping;");
		writer.println("import " + servicePackName + ".ServiceFactory;");
		writer.println("import com.butnet.myframe.actions.BaseDispatchAction;");
		writer.println("public class " + name + "Action extends BaseDispatchAction {");
		writer
				.println("	public ActionForward example(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {");
		writer.println("		" + name + "Form " + name.substring(0, 1).toLowerCase() + name.substring(1) + "Form = ("
				+ name + "Form) form;");
		writer.println("		" + name + " " + name.substring(0, 1).toLowerCase() + name.substring(1) + " = null;");
		writer.println("		ServiceFactory serviceFactory = (ServiceFactory) getServiceFactory() ;");
		writer.println("		" + name + "Service " + name.substring(0, 1).toLowerCase() + name.substring(1)
				+ "Service = serviceFactory.get" + name + "Service();");
		writer.println("		return null;");
		writer.println("	}");
		writer.println("}");
		writer.close();
	}

	private void createDaoInterface(String name) throws IOException {
		daoInterfacePackFolder.mkdirs();
		PrintWriter writer = new PrintWriter(new FileWriter(new File(daoInterfacePackFolder, name + "Dao.java")));
		writer.println("package " + daoInterfacePackName + ";");
		writer.println("import com.butnet.myframe.dao.IDao;");
		writer.println("import " + modelPackName + "." + name + ";");
		writer.println("public interface " + name + "Dao extends IDao<" + name + "> {");
		writer.println("}");
		writer.close();

		createDaoImpl(name);
		createServiceInterface(name);
	}

	private void createServiceInterface(String name) throws IOException {
		servicePackFolder.mkdirs();
		PrintWriter writer = new PrintWriter(new FileWriter(new File(servicePackFolder, name + "Service.java")));
		writer.println("package " + servicePackName + ";");
		writer.println("public interface " + name + "Service {");
		writer.println("}");
		writer.close();
		createServiceImpl(name);
	}

	public void createServiceImpl(String name) throws IOException {
		serviceImplPackFolder.mkdirs();
		PrintWriter writer = new PrintWriter(new FileWriter(new File(serviceImplPackFolder, name + "ServiceImpl.java")));
		String propertyName = name.substring(0, 1).toLowerCase() + name.substring(1) + "Dao";
		writer.println("package " + serviceImplPackName + ";");
		writer.println("import " + servicePackName + "." + name + "Service;");
		writer.println("import " + daoInterfacePackName + "." + name + "Dao;");
		writer.println("import com.butnet.myframe.service.BaseService;");
		writer.println("public class " + name + "ServiceImpl extends BaseService implements " + name + "Service {");
		writer.println("	private " + name + "Dao " + propertyName + ";");
		writer.println("	public " + name + "Dao get" + name + "Dao () {");
		writer.println("		return this." + propertyName + ";");
		writer.println("	}");
		writer.println("	public void set" + name + "Dao (" + name + "Dao " + propertyName + ") {");
		writer.println("		this." + propertyName + " = " + propertyName + ";");
		writer.println("	}");
		writer.println("}");
		writer.close();
	}

	private void createDaoImpl(String name) throws IOException {
		daoImplPackFolder.mkdirs();
		PrintWriter writer = new PrintWriter(new FileWriter(new File(daoImplPackFolder, name + "DaoImpl.java")));
		writer.println("package " + daoImplPackName + ";");
		writer.println("import " + daoInterfacePackName + "." + name + "Dao;");
		writer.println("import com.butnet.myframe.dao.BaseDao;");
		writer.println("import " + modelPackName + "." + name + ";");
		writer.println("public class " + name + "DaoImpl extends BaseDao<" + name + "> implements " + name + "Dao {");
		writer.println("}");
		writer.close();
	}
}
